/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package views;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import models.Reservation;
import org.jdesktop.swingx.table.TableColumnExt;
import tableModels.TableReservationModel;

public class frmListReservation extends javax.swing.JPanel {
    private String _numcommande;
    /**
     * Creates new form frmNewReservation
     */
    public frmListReservation() {
        initComponents();
        initTable();
    }

  private void initTable() {
        Reservation reservation = new Reservation();
        TableReservationModel model = reservation.fetchAll();
        tableReservation.setModel(model);
        TableColumnExt colId = tableReservation.getColumnExt("Numéro de commande");
        colId.setVisible(false);

    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
        @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar2 = new javax.swing.JToolBar();
        btnConsult = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tableReservation = new org.jdesktop.swingx.JXTable();

        jToolBar2.setRollover(true);

        btnConsult.setText("Consulter / Modifier");
        btnConsult.setFocusable(false);
        btnConsult.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnConsult.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnConsult.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConsultActionPerformed(evt);
            }
        });
        jToolBar2.add(btnConsult);

        tableReservation.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tableReservation);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 819, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 578, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnConsultMouseClicked(java.awt.event.MouseEvent evt) {                                        
        try {
            frmMain.affInfoReservation(this._numcommande);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(frmListClient.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(frmListClient.class.getName()).log(Level.SEVERE, null, ex);
        }
    }                                                

    
        private void  tableReservationMouseClicked(java.awt.event.MouseEvent evt) {                                          
        int ligne =  tableReservation.getSelectedRow();
        String id =  tableReservation.getModel().getValueAt(ligne, 0).toString();
        if (id != null) {
            this._numcommande = id;
        }
    }                                     
    
    private void btnConsultActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConsultActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnConsultActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnConsult;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar jToolBar2;
    private org.jdesktop.swingx.JXTable tableReservation;
    // End of variables declaration//GEN-END:variables
}
